"""
Case Type   : 系统表
Case Name   : 测试系统表GS_ENCRYPTED_COLUMNS字段与数据类型是否正确
Create At   :2024/07/08
Owner       :sungang14
Description : 
    1.查看系统表GS_ENCRYPTED_COLUMNS的表结构
    \d GS_ENCRYPTED_COLUMNS
    2.该表字段与对应字段数据类型是否如下：
         rel_id                 | oid                         
         column_name            | name                        
         column_key_id          | oid                         
         encryption_type        | tinyint                     
         data_type_original_oid | oid                         
         data_type_original_mod | integer                     
         create_date            | timestamp without time zone
    3、查看表隐含属性oid
    select oid from GS_ENCRYPTED_COLUMNS; 
Expect      : 
    1.查看系统表GS_ENCRYPTED_COLUMNS表结构成功
    2.该表字段与字段数据类型对应正确
    3.存在隐含属性oid，不报错
History     : 
"""

import sys
import os
import unittest
from yat.test import Node
from yat.test import macro

sys.path.append(sys.path[0] + "/../")
from testcase.utils.Logger import Logger
from testcase.utils.Common import Common
from testcase.utils.CommonSH import CommonSH


class IndexFileDamaged(unittest.TestCase):
    def setUp(self):
        self.logger = Logger()
        self.logger.info(f'-----{os.path.basename(__file__)} start-----')
        self.logger.info('----------------this is setup-----------------------')
        self.userNode = Node('dbuser')
        self.DB_ENV_PATH = macro.DB_ENV_PATH
        self.DB_INSTANCE_PATH = macro.DB_INSTANCE_PATH
        self.com = Common()
        self.comsh = CommonSH('dbuser')
        self.expect_result_dict = {
            'Column': ['rel_id', 'column_name', 'column_key_id', 'encryption_type', 'data_type_original_oid',
                       'data_type_original_mod', 'create_date'],
            'Type': ['oid', 'name', 'oid', 'tinyint', 'oid', 'integer', 'timestamp without time zone']
        }

    def test_Index_file_damaged(self):
        self.logger.info('----------------------------查看表结构-----------------------------')
        msg = self.comsh.execut_db_sql('\d GS_ENCRYPTED_COLUMNS')
        self.logger.info(msg)
        result_dict = self.com.format_sql_result(msg)
        self.logger.info(result_dict)
        del result_dict['Modifiers']
        self.assertDictEqual(self.expect_result_dict, result_dict)
        self.logger.info('查看表隐含属性oid')
        msg = self.comsh.execut_db_sql('select oid from GS_ENCRYPTED_COLUMNS;')
        self.logger.info(msg)
        self.assertNotIn('ERROR', msg, '查看表隐含属性oid')

    def tearDown(self):
        self.logger.info('----------------this is tearDown-----------------------')
        # 无需后置处理
        self.logger.info(f'-----{os.path.basename(__file__)} end-----')
